package org.example.coupon.controller;

import org.example.core.utils.PageUtils;
import org.example.core.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.example.coupon.entity.SeckillPromotionEntity;
import org.example.coupon.service.SeckillPromotionService;

import java.util.List;


/**
 * @author xiaojie_cc
 * @version 1.0
 */
@RestController
@RequestMapping("sms/backend/sPromotion")
public class SeckillPromotionController {
    @Autowired
    private SeckillPromotionService seckillPromotionService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R<?> list(@RequestParam(defaultValue = "1") Integer pageNum
            ,@RequestParam(defaultValue = "10") Integer pageSize
            ,@RequestParam(required = false) String title
            ,@RequestParam(required = false) Integer status ){
        PageUtils pageUtils = seckillPromotionService.querySeckillPromotionList(pageNum, pageSize, title, status);
        return R.ok(pageUtils);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R<?> info(@PathVariable("id") Long id){
        SeckillPromotionEntity seckillPromotion = seckillPromotionService.getSeckillPromotionInfo(id);
        return R.ok(seckillPromotion);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R<?> save(@RequestBody SeckillPromotionEntity seckillPromotion){
        return seckillPromotionService.addSeckillPromotion(seckillPromotion);
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R<?> update(@RequestBody SeckillPromotionEntity seckillPromotion){
        return seckillPromotionService.updateSeckillPromotion(seckillPromotion);
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R<?> delete(@RequestBody Long[] ids){

        return null;
    }

    /**
     * 获取符合时间的秒杀活动
     */
    @GetMapping("/canPromotionSession")
    public R<?> canSession() {
        return R.ok(seckillPromotionService.canPromotionSession());
    }

}
